//
//  MaintenceItem.swift
//  koolcar
//
//  Created by xiantian on 2023/10/24.
//

import UIKit

class MainCustomBtn: UIControl {
    private var titleLab: UILabel!
    private var lineImgView: UIImageView!
    public var title: String = "" {
        didSet {
            self.titleLab.text = title
            self.updateConstraints()
        }
    }
    
    override var isSelected: Bool {
        didSet {
            if isSelected {
                self.titleLab.font = UIFont.init(name: Theme.PingFangSCMedium, size: 18)
                self.titleLab.textColor = Theme.mainColor
                self.lineImgView.isHidden = false
            }else{
                self.titleLab.font = UIFont.init(name: Theme.PingFangSCRegular, size: 14)
                self.titleLab.textColor = Theme.titleLabColor
                self.lineImgView.isHidden = true
            }
            self.updateConstraints()
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        titleLab = UILabel()
        titleLab.textColor = Theme.mainColor
        titleLab.backgroundColor = UIColor.clear
        titleLab.font = UIFont.init(name: Theme.PingFangSCMedium, size: 18)
        titleLab.numberOfLines = 1
        titleLab.lineBreakMode = .byTruncatingTail
        titleLab.textAlignment = .center
        self.addSubview(titleLab)
        
        //选中标识
        lineImgView = UIImageView()
        lineImgView.contentMode = .scaleAspectFit
        lineImgView.image = UIImage.init(named: "navi_select")
        self.addSubview(lineImgView)
        
        self.addSnpLayout()
    }
    
    private func addSnpLayout(){
        titleLab.snp.makeConstraints { make in
            make.left.right.equalTo(0)
            make.top.equalTo(0)
        }
        
        lineImgView.snp.makeConstraints { make in
            make.left.right.equalTo(0)
            make.top.equalTo(titleLab.snp.bottom)
            make.bottom.equalTo(-5)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
